package com.peaker.advertisingpro.websocket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class test {


    public static void main(String[] args) {
        try {
//1.创建客户端Socket，指定服务区地址和端口
            Socket socket = new Socket("192.168.2.104", 5253);
//2.获取输出流，向服务端发送信息
            OutputStream os = socket.getOutputStream();//字节输出流
            PrintWriter pw = new PrintWriter(os);//将输出流包装为打印流
            pw.write("UserName: admin;PassWorld：123");
            pw.flush();//刷新
            socket.shutdownOutput();//关闭输出流
//3.获取输入流，并读取服务端的相应信息
            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String info = null;
            while ((info = br.readLine()) != null) {
                System.out.println("i am client,server say:" + info);
            }
//4.关闭资源
            br.close();
            is.close();
            pw.close();
            os.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
